<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <include file="public@head" />

</head>
<body>
<include file="public@nav" />

<div class="center cirWrapper clearfix">
    <include file="public@persnav" />
    <div class="pn_right_wra fr">
        <h3>
            收到的红包
        </h3>
        <h1 class="pg_total_wra">L币总额：<span class="pg_total"></span></h1>

        <ul class="pk_list">
            <li class="title">
                <span>姓名</span>
                <span>L币（个）</span>
                <span>时间</span>
            </li>
        </ul>


    </div>
</div>

<include file="public@footer" />
<include file="public@scripts" />
<script type="text/javascript" src="__TMPL__public/assets/js/personal.js"></script>
<script>
    headerMove(7);


    /**
     ** 加法函数，用来得到精确的加法结果
     ** 说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
     ** 调用：accAdd(arg1,arg2)
     ** 返回值：arg1加上arg2的精确结果
     **/
    function accAdd(arg1, arg2) {
        var r1, r2, m, c;
        try {
            r1 = arg1.toString().split(".")[1].length;
        }
        catch (e) {
            r1 = 0;
        }
        try {
            r2 = arg2.toString().split(".")[1].length;
        }
        catch (e) {
            r2 = 0;
        }
        c = Math.abs(r1 - r2);
        m = Math.pow(10, Math.max(r1, r2));
        if (c > 0) {
            var cm = Math.pow(10, c);
            if (r1 > r2) {
                arg1 = Number(arg1.toString().replace(".", ""));
                arg2 = Number(arg2.toString().replace(".", "")) * cm;
            } else {
                arg1 = Number(arg1.toString().replace(".", "")) * cm;
                arg2 = Number(arg2.toString().replace(".", ""));
            }
        } else {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", ""));
        }
        return (arg1 + arg2) / m;
    }
    //给Number类型增加一个add方法，调用起来更加方便。

    Number.prototype.add = function (arg) {
        return accAdd(arg, this);
    };

    //收到的红包
    var packs_param = {
        url:'Records/packs',
        data:{
            page:1
        }
    };
    $.JsonRpc(packs_param,function(data){
        console.log(data);
        data =  data.data.list;
        var tpl="";
        $.each(data,function(i){
            var o_createtime = data[i].o_createtime.substr(0,16).replace(/-/g,".").replace(/ /g,"-");
            tpl+=
                '<li>'+
                '<span>'+data[i].s_name+'</span>'+
                '<span class="user_package" data-user_package = "'+data[i].g_sponsor+'">'+data[i].g_sponsor+'</span>'+
                '<span>'+o_createtime+'</span>'+
                '</li>';
        });
        $(tpl).appendTo(".pk_list");
        var user_package_total = 0;
        $.each($(".user_package"),function(i){
            user_package_total = user_package_total.add($(this).data("user_package"));
        });
        $(".pg_total").html(user_package_total+"个")
    });

</script>
</body>
</html>